package com.app.core.activity;

import com.app.core.config.MyApp;
import com.app.core.presenter.ParseData;
import com.app.core.presenter.ParseDataImpl;
import com.app.core.util.LogUtils;
import com.app.core.util.ViewFinder;
import com.app.core.util.ViewUtils;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;


public abstract class BaseActivity extends AppCompatActivity implements OnClickListener {

    public static final String TAG = "BaseActivity";

    /**
     * 上下文
     */
    protected Context mContext;
    /**
     * 绑定这个activity布局的Finder
     */
    protected ViewFinder finder;
    /**
     * intent
     */
    protected Intent intent = new Intent();

    /**
     * 网络请求
     */
    protected ParseData pData = new ParseDataImpl();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }


    private void init() {
        setContentView(setContentView());
        mContext = MyApp.getInstance();
        finder = new ViewFinder(this);
        findViewbyId();
        setListener();
        getData();
        process();
    }


    @Override
    protected void onStart() {
        super.onStart();
        LogUtils.i(getActiviyName(), "onStart()");
    }

    @Override
    protected void onResume() {
        super.onResume();
        LogUtils.i(getActiviyName(), "onResume()");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        LogUtils.i(getActiviyName(), "onRestart()");
    }

    @Override
    protected void onPause() {
        super.onPause();
        LogUtils.i(getActiviyName(), "onPause()");
    }

    @Override
    protected void onStop() {
        super.onStop();
        LogUtils.i(getActiviyName(), "onStop()");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        LogUtils.i(getActiviyName(), "onDestroy()");
    }

    /**
     * activity name
     */
    public abstract String getActiviyName();

    /**
     * 加载布局
     */
    protected abstract void findViewbyId();

    /**
     * 设置监听
     */
    protected abstract void setListener();

    /**
     * 处理一般逻辑
     */
    protected abstract void process();

    /**
     * 获取数据（联网或者取本地数据库）
     */
    protected abstract void getData();

    /**
     * 展示View
     *
     * @param view
     * @return
     */
    protected BaseActivity show(final View view) {
        ViewUtils.setGone(view, false);
        return this;
    }

    /**
     * 隐藏View
     *
     * @param view
     * @return
     */
    protected BaseActivity hide(final View view) {
        ViewUtils.setGone(view, true);
        return this;
    }

    /**
     * 设置ContentView{@link #onCreate(Bundle)}
     *
     * @return 资源id
     */
    protected abstract int setContentView();


}
